import matplotlib.pyplot as plt
import random

x = range(60)
y_beijing = [random.uniform(10, 15) for i in x]
y_shanghai = [random.uniform(15, 25) for i in x]

fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(20, 8), dpi=100)

axes[0].plot(x, y_beijing, label="beijing", color="g", linestyle="-.")
axes[1].plot(x, y_shanghai, label="shanghai")

y_ticks = range(40)
x_ticks_label = [f"11点{i}分" for i in x]

axes[0].set_xticks(x[::5])
axes[0].set_yticks(y_ticks[::5])
axes[0].set_xticklabels(x_ticks_label[::5])

axes[1].set_xticks(x[::5], labels=x_ticks_label[::5])
axes[1].set_yticks(y_ticks[::5])
axes[1].set_xticklabels(x_ticks_label[::5])

axes[0].grid(True, linestyle="--", alpha=.6)
axes[1].grid(True, linestyle="-.", alpha=.2)

axes[0].set_xlabel("时间")
axes[0].set_ylabel("温度")
axes[0].set_title("北京一小时温度变化图", fontsize=20)

axes[1].set_xlabel("时间")
axes[1].set_ylabel("温度")
axes[1].set_title("上海一小时温度变化图", fontsize=20)

axes[0].legend()
axes[1].legend()

plt.savefig('temperature.png')
plt.show()
